package com.ahui.util;

import org.apache.logging.log4j.LogManager;

public class StringUtil {


    public static boolean isEmpty(String str) {
        return null == str || str.trim().length() == 0;
    }

    public static boolean isNotEmpty(String str) {
        return !isEmpty(str);
    }

    public static int charAtCount(String str) {
        int count = 0;
        String regEx = "[\\u4e00-\\u9fa5]";
        String term = str.replaceAll(regEx, "aa");
        count = term.length() - str.length();
        return count;
    }

    /**
     * poi读取合同修复
     */
    public static String originalContractReplace(String str) {

/*        str = str.replace("．", ".");
        str = str.replace("→", "一");
        str = str.replace("- -", "一");
        str = str.replace("一 一", "一");
        str = str.replace("-一", "一");
        str = str.replace("- -", "一");
        str = str.replace("一一", "一");
        str = str.replace("(大)", "(六)");
        str = str.replace("■", "");
        str = str.replace("货全", "资金");
        str = str.replace("合向", "合同");
        str = str.replace("L.", "1.");
        str = str.replace("l.", "1.");
        str = str.replace("L、", "1.");
        str = str.replace("l、", "1.");
        str = str.replace("(I)", "(1)");*/
        return str;
    }

    /**
     * 合同匹配字段修复
     */
    public static String matchContractReplace(String matchValue) {
        matchValue = matchValue.replace("\r\n", "\n");
        matchValue = matchValue.trim();
        matchValue = matchValue.replace(" ", "");
        return matchValue;
    }

    /**
     * 首页字符串处理
     */
    public static String firstPageReplace(String positionStr) {
        positionStr = positionStr.replace("\r", "");
        positionStr = positionStr.replace("\n", "");
        positionStr = positionStr.trim();
        positionStr = positionStr.replace(" ", "");
        return positionStr;
    }

    /**
     * 图片pdf文件字符串替换
     */
    public static String imgPdfItemReplace(String str) {
//        str = originalContractReplace(str);
        str = matchContractReplace(str);
        return str;
    }

    /**
     * 统计字符串str 在字符串preStr  中出现的次数
     * @param str
     * @param preStr
     * @return 返回次数
     */
    public static int showCount(String str, String preStr) {
        String parentStr = preStr;
        int count = 0;
        while (parentStr.indexOf(str) != -1) {
            count++;
            int index = parentStr.indexOf(str);
            parentStr = parentStr.substring(index + 1);
        }
        return count;
    }
}